﻿package ascript.components.animation
{
	//#########################
	// Header Includes
	//#########################
	import ascript.Game;
	import ascript.utilities.PointSimple;
	import ascript.GameComponent;
	import ascript.GameLevel;
	import ascript.GameObject;
	import Box2D.Common.Math.b2Vec2;
	
	//#########################
	// GeneralModifiers Class
	//#########################
	public class AnimationDeath extends GameComponent
	{
		//=========================
		// Constructors
		//=========================	
		public function AnimationDeath():void
		{
		}
		
		//=========================
		// Members
		//=========================
		override public function initComponent( tGame:Game, tObject:GameObject ):void
		{
			// Set Default Attributes
			defaultAttribute( tObject, "AnimationDeathIsEnabled", false );
			defaultAttribute( tObject, "AnimationDeathIsComplete", false );
			defaultAttribute( tObject, "AnimationMovieName", "NONE" );
			defaultAttribute( tObject, "AnimationDeathIndex", 0 );
			defaultAttribute( tObject, "AnimationDeathDuration", 1000 );
			defaultAttribute( tObject, "AnimationDeathTimer", 0 );
		}
		
		override public function applyAttribute( tGame:Game, tObject:GameObject, tAttribute:String ):void
		{
			switch( tAttribute )
			{
				case "AnimationDeathIsEnabled":
					if ( tObject.getAttribute( tAttribute ) )
					{
						tObject.setAttribute( "AnimationDeathTimer", tGame.time );
						
						if ( tObject.getAttribute( tObject.getAttribute( "AnimationMovieName" ) ) != null )
						{
							( tObject.getAttribute( tObject.getAttribute( "AnimationMovieName" ) ) ).setGraphic( tObject.getAttribute( "AnimationDeathIndex" ) );
						}
					}
					break;
				default:
					super.applyAttribute( tGame, tObject, tAttribute );
					break;
			}
		}
		
		override public function updateComponent( tGame:Game, tObject:GameObject, tLevel:GameLevel ):void
		{
			if ( tObject.getAttribute( "AnimationDeathIsEnabled" ) && !tObject.getAttribute( "AnimationDeathIsComplete" ) )
			{
				if ( ( tGame.time - tObject.getAttribute( "AnimationDeathTimer" ) ) >= tObject.getAttribute( "AnimationDeathDuration" ) )
				{
					tObject.setAttribute( "AnimationDeathIsComplete", true );
				}
			}
		}
	}
}